<div class="row" style="margin-top: 1%">
    <div class="box box-info container" style="padding-top: 1%;padding-bottom: 1%;">
        <div class="box-header with-border col-xs-12">
            <h3 class="boxtitle">添加中心</h3>
        </div>
        <div class="col-xs-12">
            <form class="form-horizontal">
                <div class="box-body">
                    <div class="form-group">
                        <label for="nameId" class="col-sm-4 col-xs-4 control-label">名称</label>
                        <div class="col-sm-8 col-xs-8">
                            <input type="text" class="form-control" name="name" id="nameId" placeholder="名称" style="width: 50%">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="nameId" class="col-sm-4 col-xs-4 control-label">城市</label>
                        <div class="col-sm-8 col-xs-8">
                            <input type="text" class="form-control" name="city" id="cityId" placeholder="城市" style="width: 50%">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="nameId" class="col-sm-4 col-xs-4 control-label">地址</label>
                        <div class="col-sm-8 col-xs-8">
                            <input type="text" class="form-control" name="address" id="addrId" placeholder="地址" style="width: 50%">
                        </div>
                    </div>
                </div>
                <!-- /.box-body -->
                <div class="box-footer" style="text-align: center;display: flex;justify-content: center;align-items:center;">
                    <button type="button" class="btn btn-default btn-cancel button button--aylen button--border-thin button--round-s">取消</button>
                    <button type="button" class="btn btn-info btn-save button button--aylen button--border-thin button--round-s">保存</button>
                </div>
                <!-- /.box-footer -->
            </form>
        </div>
    </div>
</div>
<!-- Horizontal Form -->
<!--<div class="box box-info">-->
    <!--<div class="box-header with-border">-->
        <!--<h3 class="box-title">添加中心</h3>-->
    <!--</div>-->
    <!--&lt;!&ndash; /.box-header &ndash;&gt;-->
    <!--&lt;!&ndash; form start &ndash;&gt;-->
    <!--<form class="form-horizontal">-->
        <!--<div class="box-body">-->
            <!--<div class="form-group">-->
                <!--<label for="nameId" class="col-sm-2 control-label">名称</label>-->

                <!--<div class="col-sm-10">-->
                    <!--<input type="text" class="form-control" name="name" id="nameId" placeholder="名称">-->
                <!--</div>-->
            <!--</div>-->
            <!--<div class="form-group">-->
                <!--<label for="cityId" class="col-sm-2 control-label">城市</label>-->

                <!--<div class="col-sm-10">-->
                    <!--<input type="text" class="form-control" name="city" id="cityId" placeholder="城市">-->
                <!--</div>-->
            <!--</div>-->
            <!--<div class="form-group">-->
                <!--<label for="addrId" class="col-sm-2 control-label">地址</label>-->

                <!--<div class="col-sm-10">-->
                    <!--<input type="text" class="form-control" name="address" id="addrId" placeholder="地址">-->
                <!--</div>-->
            <!--</div>-->
        <!--</div>-->
        <!--&lt;!&ndash; /.box-body &ndash;&gt;-->
        <!--<div class="box-footer">-->
            <!--<button type="button" class="btn btn-default btn-cancel">Cancel</button>-->
            <!--<button type="button" class="btn btn-info pull-right btn-save">Save</button>-->
        <!--</div>-->
        <!--&lt;!&ndash; /.box-footer &ndash;&gt;-->
    <!--</form>-->
<!--</div>-->
<script type="text/javascript">
    $(function(){
        //修改时添加如下代码(注意先后顺序)
        var rowData=$("#mainContentId").data("data");
        if(rowData)doInitEditFormData(rowData);

        $(".box-footer")
            .on("click",".btn-save",doSaveOrUpdate)
            .on("click",".btn-cancel",doCancel);
    });
    function doInitEditFormData(data){
        console.log("data",data);
        //1.初始化角色自身信息
        $("#nameId").val(data.name);
        $("#cityId").val(data.city);
        $("#addrId").val(data.address);
    }
    function doCancel(){
        var url="center/center_list";
        $("#mainContentId")
            .load(url,function(){
                $("#mainContentId").removeData();
            });
    }

    function doSaveOrUpdate(){
        //1.参数(表单数据)
        var params=doGetEditFormData();
        if(!params.name.trim()){
            alert("中心名不能为空");
            return;
        }
        if(!params.city.trim()){
            alert("城市不能为空");
            return;
        }
        if(!params.address.trim()){
            alert("地址不能为空");
            return;
        }

        var data=$("#mainContentId").data("data");
        debugger
        if(data)params.centerId=data.centerId;
        //2.url
        var url="cy/center/saveObject";
        //3.ajax request
        $.post(url,params,function(result){
            if(result.state==1){
                alert(result.message);
                doCancel();
            }else{
                alert(result.message);
            }
        })
    }
    function doGetEditFormData(){
        //1.获取角色自身信息
        var params={
            name:$("#nameId").val(),
            city:$("#cityId").val(),
            address:$("#addrId").val()
        }
        return params;
    }

</script>
    
    
    
    
    
    
    
    